﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Wpf.CommonTools.EnumExtension
{
    public static class EnumExtension
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public static T[] GetFlags<T>(this T value) where T : struct , IConvertible
        {
            return Enum.GetValues(typeof(T))
                .OfType<T>()
                .Where(t => (Convert.ToInt32(t) & Convert.ToInt32(value)) == Convert.ToInt32(t))
                .ToArray();
        }
    }
}
